package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/8/10 16:58
 */
public class LS213 {
    public int rob(int[] nums) {
        if (nums.length == 1) {
            return nums[0];
        } else if (nums.length==2){
            return Math.max(nums[0],nums[1]);
        }

        return Math.max(get(nums,0,nums.length-2),get(nums,1,nums.length-1));
    }

    public static int get(int[] nums,int start,int end) {
        int first = nums[start];
        int second = nums[start+1];

        for (int i = start + 2; i <= end; i++) {
            int temp = second;
            second = Math.max(first + nums[i],second);
            first = temp;
        }

        return second;
    }
}
